#include "mygui.h"

//加载屏幕函数
static void SetupScrScreen(lv_ui* ui);
static void SetupScrScreen1(lv_ui* ui);

//事件回调函数
static void SaveButtonEventCb(lv_event_t* event);
static void CalendarUpateDateEventCb(lv_event_t* event);
static void DateTextAreaEventCb(lv_event_t* event);
static void CreateGetSensorDataTimer(uint32_t num);
// 全局组件集合对象
static lv_ui guider_ui;

static RtcTime_t rtc_time;

/**
 * @desc  : 初始化
 * @date  : 2025-07-02
 * @author: AnRui
 * @note  :
 */
void MyGuiInit(void) {
    GetRtcTime(&rtc_time);
    printf("rtc_time %d %d %d %d %d %d", rtc_time.year, rtc_time.month, rtc_time.day, rtc_time.hour, rtc_time.minute, rtc_time.second);
    SetupScrScreen1(&guider_ui);
    lv_scr_load(guider_ui.screen1);
}


/**
 * @desc  : 获取传感器数据的定时器的回调函数
 * @date  : 2025-07-03
 * @author: AnRui
 * @note  :
 */
static void  GetSensorDataTimerHandler(lv_timer_t* timer) {
    // 检查屏幕是否有效且可见（避免在屏幕切换后更新UI）
      // lv_obj_is_valid() 函数实现可以看出，LVGL 通过遍历所有显示设备的屏幕及其子对象来判断一个对象是否有效
      // lv_obj_is_visible() 检查对象是否可见（即使存在，但可能被隐藏或在屏幕外）
    if (!lv_obj_is_valid(guider_ui.screen) || !lv_obj_is_visible(guider_ui.screen)) return;
    SensorData_t sensorData;
    GetSensorData(&sensorData);
    lv_label_set_text_fmt(guider_ui.screenTempValueLabel, "%02d", (int)sensorData.temp);
    lv_label_set_text_fmt(guider_ui.screenHumiValueLabel, "%02d", (int)sensorData.humi);
}

/**
 * @desc  : 设置一个每 num ms获取一次传感器数据的定时器
 * @date  : 2025-07-03
 * @author: AnRui
 * @note  :
 */
static void CreateGetSensorDataTimer(uint32_t num) {
    // 先删除旧定时器（如果存在）
    if (guider_ui.screenGetSensorDataTimer != NULL) return;
    guider_ui.screenGetSensorDataTimer = lv_timer_create(GetSensorDataTimerHandler, num, NULL);  //第二个参数（周期）是以毫秒为单位
}


/**
 * @desc  : 绘制屏幕screen
 * @date  : 2025-07-01
 * @author: AnRui
 * @param : ui - {参数说明}:
 * @note  :
 */
static void SetupScrScreen(lv_ui* ui) {
    /************************************************screen**************************************/
    ui->screen = lv_obj_create(NULL);
    lv_obj_remove_style_all(ui->screen);
    lv_obj_set_size(ui->screen, lv_pct(100), lv_pct(100));  // 设置为屏幕大小
    //Write style for screen
    lv_obj_set_style_bg_color(ui->screen, lv_color_hex(0x0000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui->screen, 255, LV_PART_MAIN);
    lv_obj_set_style_pad_all(ui->screen, 0, 0);
    lv_obj_set_style_border_width(ui->screen, 0, LV_PART_MAIN);
    /************************************************screenTitleLable**************************************/
    ui->screenTitleLable = lv_label_create(ui->screen);
    lv_obj_set_style_text_align(ui->screenTitleLable, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_align(ui->screenTitleLable, LV_ALIGN_TOP_MID, 0, 10);
    lv_label_set_text(ui->screenTitleLable, "温湿度");
    lv_obj_set_style_text_font(ui->screenTitleLable, &SourceHanSerifSC_SemiBold_28, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_color(ui->screenTitleLable, lv_color_hex(0xffffff), LV_PART_MAIN); //设置字体颜色
    /************************************************screenLine**************************************/
    //线条 需要计算开始和结束的坐标
    ui->screenLine = lv_line_create(ui->screen);
    static lv_point_t line_points[2];
    line_points[0].x = 10;
    line_points[0].y = 0;
    line_points[1].x = LV_HOR_RES - 10;
    line_points[1].y = 0;
    lv_line_set_points(ui->screenLine, line_points, 2);
    lv_obj_set_style_line_color(ui->screenLine, lv_color_hex(0xFFFFFF), 0);  // 白色线条
    lv_obj_set_style_line_width(ui->screenLine, 2, 0);                        // 线宽1px
    lv_obj_set_style_line_opa(ui->screenLine, LV_OPA_20, 0);
    lv_obj_align(ui->screenLine, LV_ALIGN_OUT_TOP_MID, 0, 48);

    /***************************************screenTempContainer***********************************************/
    ui->screenTempContainer = lv_obj_create(ui->screen);
    lv_obj_remove_style_all(ui->screenTempContainer);
    lv_obj_set_style_pad_left(ui->screenTempContainer, 20, LV_PART_MAIN);
    lv_obj_set_style_pad_right(ui->screenTempContainer, 30, LV_PART_MAIN);
    lv_obj_set_style_bg_opa(ui->screenTempContainer, 0, LV_PART_MAIN);
    lv_obj_set_style_width(ui->screenTempContainer, lv_pct(100), LV_PART_MAIN);
    lv_obj_set_style_height(ui->screenTempContainer, LV_SIZE_CONTENT, LV_PART_MAIN);//LV_SIZE_CONTENT
    lv_obj_align(ui->screenTempContainer, LV_ALIGN_OUT_TOP_LEFT, 0, 150);

    ui->screenTempImg = lv_img_create(ui->screenTempContainer);
    lv_obj_set_style_width(ui->screenTempImg, 42, LV_PART_MAIN);
    lv_obj_set_style_height(ui->screenTempImg, 42, LV_PART_MAIN);
    lv_img_set_src(ui->screenTempImg, &temp_img);
    lv_obj_align(ui->screenTempImg, LV_ALIGN_LEFT_MID, 0, 0);

    ui->screenTempDescLabel = lv_label_create(ui->screenTempContainer);
    lv_label_set_text_fmt(ui->screenTempDescLabel, "温度(℃)");
    lv_obj_set_style_text_font(ui->screenTempDescLabel, &SourceHanSerifSC_SemiBold_26, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_align(ui->screenTempDescLabel, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_set_style_text_color(ui->screenTempDescLabel, lv_color_hex(0xffffff), 0); //设置字体颜色
    lv_obj_align(ui->screenTempDescLabel, LV_ALIGN_LEFT_MID, 60, 0);
    ui->screenTempValueLabel = lv_label_create(ui->screenTempContainer);
    lv_label_set_text_fmt(ui->screenTempValueLabel, "%d", 0);
    lv_obj_set_style_text_font(ui->screenTempValueLabel, &SourceHanSerifSC_SemiBold_40, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_align(ui->screenTempValueLabel, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_set_style_text_color(ui->screenTempValueLabel, lv_color_hex(0xffffff), 0); //设置字体颜色
    lv_obj_align(ui->screenTempValueLabel, LV_ALIGN_RIGHT_MID, 0, 0);

    /***************************************screenHumiContainer***********************************************/
    ui->screenHumiContainer = lv_obj_create(ui->screen);
    lv_obj_remove_style_all(ui->screenHumiContainer);
    lv_obj_set_style_pad_left(ui->screenHumiContainer, 20, LV_PART_MAIN);
    lv_obj_set_style_pad_right(ui->screenHumiContainer, 30, LV_PART_MAIN);
    // lv_obj_set_style_bg_opa(ui->screenHumiContainer, 255, LV_PART_MAIN);
    lv_obj_set_style_width(ui->screenHumiContainer, lv_pct(100), LV_PART_MAIN);
    lv_obj_set_style_height(ui->screenHumiContainer, LV_SIZE_CONTENT, LV_PART_MAIN);//LV_SIZE_CONTENT
    // lv_obj_set_style_bg_color(ui->screenHumiContainer, lv_color_hex(0x333333), LV_PART_MAIN);
    lv_obj_align(ui->screenHumiContainer, LV_ALIGN_OUT_BOTTOM_MID, 0, 250);


    ui->screenHumiImg = lv_img_create(ui->screenHumiContainer);
    lv_obj_set_style_width(ui->screenHumiImg, 42, LV_PART_MAIN);
    lv_obj_set_style_height(ui->screenHumiImg, 42, LV_PART_MAIN);
    lv_img_set_src(ui->screenHumiImg, &humi_img);
    lv_obj_align(ui->screenHumiImg, LV_ALIGN_LEFT_MID, 0, 0);

    ui->screenHumiDescLabel = lv_label_create(ui->screenHumiContainer);
    lv_label_set_text_fmt(ui->screenHumiDescLabel, "湿度(℃)");
    lv_obj_set_style_text_font(ui->screenHumiDescLabel, &SourceHanSerifSC_SemiBold_26, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_align(ui->screenHumiDescLabel, LV_TEXT_ALIGN_LEFT, 0);
    lv_obj_set_style_text_color(ui->screenHumiDescLabel, lv_color_hex(0xffffff), 0); //设置字体颜色
    lv_obj_align(ui->screenHumiDescLabel, LV_ALIGN_LEFT_MID, 60, 0);

    ui->screenHumiValueLabel = lv_label_create(ui->screenHumiContainer);
    lv_label_set_text_fmt(ui->screenHumiValueLabel, "%d", 0);
    lv_obj_set_style_text_font(ui->screenHumiValueLabel, &SourceHanSerifSC_SemiBold_40, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_align(ui->screenHumiValueLabel, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_set_style_text_color(ui->screenHumiValueLabel, lv_color_hex(0xffffff), 0); //设置字体颜色
    lv_obj_align(ui->screenHumiValueLabel, LV_ALIGN_RIGHT_MID, 0, 0);

    /***************************************screenTimer***********************************************/
    CreateGetSensorDataTimer(1000);
}


/**
 * @desc  : 绘制屏幕screen1
 * @date  : 2025-07-03
 * @author: AnRui
 * @param : ui - {参数说明}:
 * @note  :
 */
static void SetupScrScreen1(lv_ui* ui) {
    /************************************************screen1**************************************/
    ui->screen1 = lv_obj_create(NULL);
    lv_obj_remove_style_all(ui->screen1);
    lv_obj_set_size(ui->screen1, lv_pct(100), lv_pct(100));  // 设置为屏幕大小
    //Write style for screen
    lv_obj_set_style_bg_color(ui->screen1, lv_color_hex(0x0000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui->screen1, 255, LV_PART_MAIN);
    lv_obj_set_style_pad_all(ui->screen1, 0, 0);
    lv_obj_set_style_border_width(ui->screen1, 0, LV_PART_MAIN);
    /************************************************screen1TitleLable**************************************/
    ui->screen1TitleLable = lv_label_create(ui->screen1);
    lv_obj_set_style_text_align(ui->screen1TitleLable, LV_TEXT_ALIGN_CENTER, 0);
    // lv_obj_set_style_border_width(ui->screen1TitleLable, 1, 0);
    // lv_obj_set_style_border_color(ui->screen1TitleLable, lv_color_hex(0x333333), 0);
    lv_obj_align(ui->screen1TitleLable, LV_ALIGN_TOP_MID, 0, 10);
    lv_label_set_text(ui->screen1TitleLable, "设置时间");
    lv_obj_set_style_text_font(ui->screen1TitleLable, &SourceHanSerifSC_SemiBold_28, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_color(ui->screen1TitleLable, lv_color_hex(0xffffff), LV_PART_MAIN); //设置字体颜色
    /************************************************screen1Line**************************************/
    //线条 需要计算开始和结束的坐标
    ui->screen1Line = lv_line_create(ui->screen1);
    static lv_point_t line_points[2];
    line_points[0].x = 10;
    line_points[0].y = 0;
    line_points[1].x = LV_HOR_RES - 10;
    line_points[1].y = 0;
    lv_line_set_points(ui->screen1Line, line_points, 2);
    lv_obj_set_style_line_color(ui->screen1Line, lv_color_hex(0xFFFFFF), 0);  // 白色线条
    lv_obj_set_style_line_width(ui->screen1Line, 2, 0);                        // 线宽1px
    lv_obj_set_style_line_opa(ui->screen1Line, LV_OPA_20, 0);
    lv_obj_align(ui->screen1Line, LV_ALIGN_OUT_TOP_MID, 0, 48);
    /***************************************screen1DateContainer***********************************************/
    ui->screen1DateContainer = lv_obj_create(ui->screen1);
    lv_obj_remove_style_all(ui->screen1DateContainer);
    lv_obj_set_style_pad_left(ui->screen1DateContainer, 20, LV_PART_MAIN);
    lv_obj_set_style_pad_right(ui->screen1DateContainer, 20, LV_PART_MAIN);
    lv_obj_set_style_bg_opa(ui->screen1DateContainer, 0, LV_PART_MAIN);
    // lv_obj_set_style_bg_color(ui->screen1DateContainer, lv_color_hex(0x333300), LV_PART_MAIN);
    lv_obj_set_style_width(ui->screen1DateContainer, lv_pct(100), LV_PART_MAIN);
    lv_obj_set_style_height(ui->screen1DateContainer, LV_SIZE_CONTENT, LV_PART_MAIN);//LV_SIZE_CONTENT
    lv_obj_align_to(ui->screen1DateContainer, ui->screen1Line, LV_ALIGN_OUT_BOTTOM_MID, 0, 90);
    lv_obj_align(ui->screen1DateContainer, LV_ALIGN_OUT_TOP_MID, 0, 130);

    ui->screen1DateDescLabel = lv_label_create(ui->screen1DateContainer);
    lv_label_set_text_fmt(ui->screen1DateDescLabel, "日期");
    lv_obj_set_style_text_font(ui->screen1DateDescLabel, &SourceHanSerifSC_SemiBold_26, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_align(ui->screen1DateDescLabel, LV_TEXT_ALIGN_LEFT, 0);
    lv_obj_set_style_text_color(ui->screen1DateDescLabel, lv_color_hex(0xffffff), 0); //设置字体颜色
    lv_obj_set_style_width(ui->screen1DateDescLabel, 130, LV_PART_MAIN);
    lv_obj_align(ui->screen1DateDescLabel, LV_ALIGN_LEFT_MID, 0, 0);



    char textBuf[16];
    ui->screen1DateValueTextarea = lv_textarea_create(ui->screen1DateContainer);
    lv_obj_remove_style_all(ui->screen1DateValueTextarea);
    lv_obj_set_style_width(ui->screen1DateValueTextarea, 150, 0);
    lv_textarea_set_one_line(ui->screen1DateValueTextarea, true);
    sprintf(textBuf, "%d-%02d-%02d", rtc_time.year, rtc_time.month, rtc_time.day);
    printf("textBuf%s\r\n ", textBuf);
    lv_obj_set_style_text_font(ui->screen1DateValueTextarea, &SourceHanSerifSC_SemiBold_26, 0);
    lv_obj_set_style_text_color(ui->screen1DateValueTextarea, lv_color_hex(0xffffff), 0);
    lv_textarea_set_text(ui->screen1DateValueTextarea, textBuf);
    lv_obj_align(ui->screen1DateValueTextarea, LV_ALIGN_RIGHT_MID, 0, 0);
    lv_obj_add_event_cb(ui->screen1DateValueTextarea, DateTextAreaEventCb, LV_EVENT_CLICKED, NULL);  // 为对象分配事件及其处理函数


    /***************************************screen1TimeContainer***********************************************/
    ui->screen1TimeContainer = lv_obj_create(ui->screen1);
    lv_obj_remove_style_all(ui->screen1TimeContainer);
    lv_obj_set_style_pad_left(ui->screen1TimeContainer, 20, LV_PART_MAIN);
    lv_obj_set_style_pad_right(ui->screen1TimeContainer, 0, LV_PART_MAIN);
    lv_obj_set_style_bg_opa(ui->screen1TimeContainer, 0, LV_PART_MAIN);
    // lv_obj_set_style_bg_color(ui->screen1TimeContainer, lv_color_hex(0x333300), LV_PART_MAIN);
    lv_obj_set_style_width(ui->screen1TimeContainer, lv_pct(100), LV_PART_MAIN);
    lv_obj_set_style_height(ui->screen1TimeContainer, LV_SIZE_CONTENT, LV_PART_MAIN);//LV_SIZE_CONTENT
    lv_obj_align_to(ui->screen1TimeContainer, ui->screen1Line, LV_ALIGN_OUT_BOTTOM_MID, 0, 90);
    lv_obj_align(ui->screen1TimeContainer, LV_ALIGN_OUT_TOP_MID, 0, 240);


    ui->screen1TimeDescLabel = lv_label_create(ui->screen1TimeContainer);
    lv_label_set_text_fmt(ui->screen1TimeDescLabel, "时间");
    lv_obj_set_style_text_font(ui->screen1TimeDescLabel, &SourceHanSerifSC_SemiBold_26, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_align(ui->screen1TimeDescLabel, LV_TEXT_ALIGN_LEFT, 0);
    lv_obj_set_style_text_color(ui->screen1TimeDescLabel, lv_color_hex(0xffffff), 0); //设置字体颜色
    lv_obj_set_style_width(ui->screen1TimeDescLabel, 130, LV_PART_MAIN);
    lv_obj_align(ui->screen1TimeDescLabel, LV_ALIGN_LEFT_MID, 0, 0);


    static const char* hourOpts = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n"
        "13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23";
    ui->screen1HourDropDown = lv_dropdown_create(ui->screen1TimeContainer);
    lv_obj_remove_style_all(ui->screen1HourDropDown);
    lv_dropdown_set_options_static(ui->screen1HourDropDown, hourOpts);
    lv_dropdown_set_dir(ui->screen1HourDropDown, LV_DIR_RIGHT);
    lv_dropdown_set_symbol(ui->screen1HourDropDown, NULL);
    lv_obj_set_style_bg_opa(ui->screen1HourDropDown, LV_OPA_0, 0);
    lv_obj_set_style_width(ui->screen1HourDropDown, 80, 0);
    // lv_obj_set_style_border_width(ui->screen1HourDropDown, 1, 0);
    lv_obj_set_style_text_font(ui->screen1HourDropDown, &SourceHanSerifSC_SemiBold_26, 0);
    lv_obj_set_style_text_color(ui->screen1HourDropDown, lv_color_hex(0xFFFFFF), 0);
    lv_obj_set_style_text_align(ui->screen1HourDropDown, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_set_style_bg_color(lv_dropdown_get_list(ui->screen1HourDropDown), lv_color_hex(0xc2a266), LV_PART_SELECTED);
    lv_dropdown_set_selected(ui->screen1HourDropDown, rtc_time.hour);// 根据值来设置 默认选中哪个
    lv_obj_align(ui->screen1HourDropDown, LV_ALIGN_LEFT_MID, 105, 0);

    ui->screen1TimeSpaceLabel = lv_label_create(ui->screen1TimeContainer);
    lv_label_set_text_fmt(ui->screen1TimeSpaceLabel, ":");
    lv_obj_set_style_border_width(ui->screen1TimeSpaceLabel, 1, 0);
    lv_obj_set_style_width(ui->screen1TimeSpaceLabel, 24, 0);
    lv_obj_set_style_text_font(ui->screen1TimeSpaceLabel, &SourceHanSerifSC_SemiBold_26, LV_PART_MAIN); // 设置字体
    lv_obj_set_style_text_align(ui->screen1TimeSpaceLabel, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_set_style_text_color(ui->screen1TimeSpaceLabel, lv_color_hex(0xffffff), 0); //设置字体颜色
    // lv_obj_set_style_width(ui->screen1TimeDescLabel, 130, LV_PART_MAIN);
    lv_obj_align_to(ui->screen1TimeSpaceLabel, ui->screen1HourDropDown, LV_ALIGN_OUT_RIGHT_MID, 0, 0);

    static const char* minuteOpts = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n"
        "13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"
        "25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n"
        "37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n"
        "49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59";
    ui->screen1MinuteDropDown = lv_dropdown_create(ui->screen1TimeContainer);
    lv_obj_remove_style_all(ui->screen1MinuteDropDown);
    lv_dropdown_set_options_static(ui->screen1MinuteDropDown, minuteOpts);
    lv_dropdown_set_dir(ui->screen1MinuteDropDown, LV_DIR_LEFT);
    lv_dropdown_set_symbol(ui->screen1MinuteDropDown, NULL);
    lv_obj_set_style_bg_opa(ui->screen1MinuteDropDown, LV_OPA_0, 0);
    lv_obj_set_style_width(ui->screen1MinuteDropDown, 80, 0);
    // lv_obj_set_style_border_width(ui->screen1MinuteDropDown, 1, 0);
    lv_obj_set_style_text_font(ui->screen1MinuteDropDown, &SourceHanSerifSC_SemiBold_26, 0);
    lv_obj_set_style_text_color(ui->screen1MinuteDropDown, lv_color_hex(0xFFFFFF), 0);
    lv_obj_set_style_text_align(ui->screen1MinuteDropDown, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_set_style_bg_color(lv_dropdown_get_list(ui->screen1MinuteDropDown), lv_color_hex(0xc2a266), LV_PART_SELECTED);
    lv_dropdown_set_selected(ui->screen1MinuteDropDown, rtc_time.minute);// 根据值来设置 默认选中哪个
    lv_obj_align_to(ui->screen1MinuteDropDown, ui->screen1TimeSpaceLabel, LV_ALIGN_OUT_RIGHT_MID, 0, 0);


    /***************************************screen1SaveButton***********************************************/


    ui->screen1SaveButton = lv_btn_create(ui->screen1);
    lv_obj_align(ui->screen1SaveButton, LV_ALIGN_BOTTOM_MID, 0, -50);
    lv_obj_set_size(ui->screen1SaveButton, 140, 46);//30 单位是像素  lv_pct(50) 父组件的50%
    lv_obj_set_style_border_width(ui->screen1SaveButton, 0, LV_PART_MAIN);                           // 边框宽度为2px
    lv_obj_set_style_radius(ui->screen1SaveButton, 10, 0);
    lv_obj_set_style_bg_color(ui->screen1SaveButton, lv_color_hex(0xbda063), LV_PART_MAIN);//設置点击状态不同的背景色
    //lv_obj_set_style_bg_color(ui->screen1SaveButton, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_PRESSED);//設置点击状态不同的背景色
    lv_obj_set_style_bg_color(ui->screen1SaveButton, lv_color_hex(0xAAAAAA), LV_STATE_DISABLED);// 设置禁用状态背景色（灰色）
    lv_obj_add_event_cb(ui->screen1SaveButton, SaveButtonEventCb, LV_EVENT_CLICKED, NULL);

    ui->screen1SaveButtonLabel = lv_label_create(ui->screen1SaveButton);
    lv_label_set_text(ui->screen1SaveButtonLabel, "保存");
    lv_obj_set_style_text_font(ui->screen1SaveButtonLabel, &SourceHanSerifSC_SemiBold_26, 0);
    lv_obj_center(ui->screen1SaveButtonLabel);

}


/**
 * @desc  : 保存按钮回调事件
 * @date  : 2025-07-03
 * @author: AnRui
 * @param : event - {参数说明}:
 * @note  :
 */
static void SaveButtonEventCb(lv_event_t* event) {
    lv_obj_t* btn = lv_event_get_current_target(event);  // 获取当前按钮
    // 1. 禁用按钮，防止连击
    lv_obj_add_state(btn, LV_STATE_DISABLED);
    rtc_time.hour = lv_dropdown_get_selected(guider_ui.screen1HourDropDown);
    rtc_time.minute = lv_dropdown_get_selected(guider_ui.screen1MinuteDropDown);
    printf("rtc_time %d %d %d %d %d %d", rtc_time.year, rtc_time.month, rtc_time.day, rtc_time.hour, rtc_time.minute, rtc_time.second);
    SetRtcTime(&rtc_time);
    // lv_obj_clear_state(btn, LV_STATE_DISABLED);  // 恢复按钮状态
    // 切换到主屏幕（优化：避免重复创建屏幕）
    if (guider_ui.screen == NULL) {
        SetupScrScreen(&guider_ui);
    }
    lv_scr_load_anim(guider_ui.screen, LV_SCR_LOAD_ANIM_FADE_IN, 200, 10, true);
    guider_ui.screen1 = NULL;
}


/**
 * @desc  : 保存日期的textare回调事件
 * @date  : 2025-07-03
 * @author: AnRui
 * @param : event - {参数说明}:
 * @note  :
 */
void DateTextAreaEventCb(lv_event_t* event) {
    lv_obj_t* ta = lv_event_get_target(event);
    lv_obj_t* calendar = lv_calendar_create(lv_layer_top());   // 在 lv_layer_top 层上创建日历对象
    lv_obj_set_size(calendar, LV_HOR_RES, LV_VER_RES - 30);
    lv_obj_align(calendar, LV_ALIGN_TOP_MID, 0, 30);
    // 自定义年份
    lv_calendar_header_dropdown_create(calendar);
    static const char* years = "2025\n2024\n2023\n2022\n2021\n2020\n2019";
    lv_calendar_header_dropdown_set_year_list(calendar, years);
    lv_calendar_set_today_date(calendar, rtc_time.year, rtc_time.month, rtc_time.day);
    lv_calendar_set_showed_date(calendar, rtc_time.year, rtc_time.month);  // 给日历的指定打开时显示的日期
    lv_obj_add_event_cb(calendar, CalendarUpateDateEventCb, LV_EVENT_VALUE_CHANGED, ta);
}


/**
 * @desc  : 日历更新日期回调事件
 * @date  : 2025-07-03
 * @author: AnRui
 * @param : event - {参数说明}:
 * @note  :
 */
static void CalendarUpateDateEventCb(lv_event_t* event) {
    lv_obj_t* calendar = lv_event_get_current_target(event);  // 必须是lv_event_get_current_target不能是lv_event_get_target
    lv_event_code_t code = lv_event_get_code(event);
    lv_obj_t* ta = lv_event_get_user_data(event);

    if (code == LV_EVENT_VALUE_CHANGED) {
        char buf[20];
        lv_calendar_date_t date;
        lv_calendar_get_pressed_date(calendar, &date);
        memset(buf, 0, sizeof(buf));
        sprintf(buf, "%d-%02d-%02d", date.year, date.month, date.day);
        lv_textarea_set_text(ta, buf);
        rtc_time.year = date.year;
        rtc_time.month = date.month;
        rtc_time.day = date.day;
    }
    lv_obj_del(calendar);           // 删除对象及其所有子对象
}
